/*******************************************************************************
 * Copyright (c) 2008 CEA LIST.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA LIST - initial API and implementation
 *******************************************************************************/

package com.cea.papyrus.core.tabbedproperties;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;

import com.cea.papyrus.core.editpart.IUMLElementEditPart;
import com.cea.papyrus.core.tabbedproperties.composite.TextCompositeWithModelAccessor;

/**
 * Section to edit string features
 */
public class StringPropertyTextSection extends PropertyViewSection {

	/** text composite to display the feature */
	final TextCompositeWithModelAccessor composite;

	/**
	 * Creates a new StringPropertyTextSection.
	 */
	public StringPropertyTextSection(String label, int featureID) {
		composite = new TextCompositeWithModelAccessor(label, featureID);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) {
		super.createControls(parent, tabbedPropertySheetPage);
		composite.createContent(parent, tabbedPropertySheetPage.getWidgetFactory());
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void refresh() {
		super.refresh();
		composite.refresh();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void dispose() {
		if(composite!=null) {
			composite.dispose();
		}
		super.dispose();
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void setInput(IWorkbenchPart part, ISelection selection) {
		super.setInput(part, selection);
		assert (selection instanceof IStructuredSelection) : "selection should implements IStructuredSelection";
		Object input = ((IStructuredSelection) selection).getFirstElement();
		if (input instanceof IUMLElementEditPart) {
			composite.setElement(((IUMLElementEditPart<?>) input).getUmlElement());	
		}
	}
	
	
}
